package com.hd.tiyu.yuejian.Fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hd.tiyu.yuejian.Adapter.CourseAdpater;
import com.hd.tiyu.yuejian.JavaBean.ClubIntro;
import com.hd.tiyu.yuejian.Model.ListsModel;
import com.hd.tiyu.yuejian.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by love on 2017/10/13.
 */

public class ClubClassFragment extends Fragment {
    private View view;
    private RecyclerView recyclerView;
    private String id;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.clubclasstab,container,false);
        Bundle bundle=getArguments();
        id=bundle.getString("id");
        initViews();
        initEvents();
        initData();
        return view;
    }

    private void initViews() {
        recyclerView=view.findViewById(R.id.classlist);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }


    private void initEvents() {
        ListsModel listsMdoel=new ListsModel();
        Call<ClubIntro>call=listsMdoel.getClubIntro(id);
        call.enqueue(new Callback<ClubIntro>() {
            @Override
            public void onResponse(Call<ClubIntro> call, Response<ClubIntro> response) {
                ClubIntro data=response.body();
                List<ClubIntro.ClubcourseEntity> course=data.getClubcourse();
                recyclerView.setAdapter(new CourseAdpater(getActivity(),course));
            }

            @Override
            public void onFailure(Call<ClubIntro> call, Throwable t) {

            }
        });
    }


    private void initData() {
    }

}
